package com.hbisdt.cet.sample.controller;

import com.hbisdt.cet.sample.service.CarbonCollectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 *
 * @author : 教学案例
 * @version : 1.0
 * @date : 2025-05-08 15:52
 */
@RestController
public class CarbonCollectController {
    @Autowired
    private CarbonCollectService carbonCollectService;

    @GetMapping("/steelProduce")
    public String steelProduce() throws InterruptedException {
        System.out.println("模拟钢铁生产过程...");
        Long startTime = System.currentTimeMillis();
        System.out.println("生产步骤1...");
        //在步骤1后开始异步采集碳排放数据
        carbonCollectService.collect();
        System.out.println("生产步骤2...");
        Long endTime = System.currentTimeMillis();
        System.out.println("主流程耗时：" + (endTime - startTime));
        return "steel success";
    }
    @GetMapping("/steelProcess")
    public String steelProcess() throws InterruptedException, ExecutionException {
        System.out.println("模拟钢铁生产过程...");
        Long startTime = System.currentTimeMillis();
        Future<Integer> resultA = carbonCollectService.processA();
        Future<Integer> resultB = carbonCollectService.processB();
        int result = resultA.get() + resultB.get();
        System.out.println("碳排放 统计+计算分析结果为:" + result);
        Long endTime = System.currentTimeMillis();
        System.out.println("主流程耗时：" + (endTime - startTime));
        return "produce success";
    }
}
